using UnityEngine;

public class FightingTask : BaseTask
{
	public static FightingTask instance;

	public override void MyUpdate()
	{
		if (timebegin)
		{
			stoptime += Time.deltaTime;
			if (Mathf.FloorToInt(stoptime) == 1)
			{
				timeone();
			}
			else if (Mathf.FloorToInt(stoptime) == 3)
			{
				timetwo();
			}
			else if (Mathf.FloorToInt(stoptime) == 4)
			{
				timethree();
			}
			else if (Mathf.FloorToInt(stoptime) == 5)
			{
				timefour();
			}
			if (stoptime >= 5f)
			{
				stoptime = 0f;
				timebegin = false;
			}
		}
		else if (!FinishState)
		{
			base.MyUpdate();
			if (AIPool.instance.ishaveboss && !AIPool.instance.CheckBoss())
			{
				AIPool.instance.SetAllFalse();
				FinishState = true;
				isSuccess = true;
			}
			if (FriendPool.instance.ishaveboss && !FriendPool.instance.CheckFriBoss())
			{
				FriendPool.instance.SetAllFalse();
				TasksController.instance.gameover(issucces: false);
				isSuccess = false;
			}
		}
	}

	public override void MyStart()
	{
		base.MyStart();
		if (instance == null)
		{
			instance = this;
		}
		AIPool.instance.ishaveboss = false;
		FriendPool.instance.ishaveboss = false;
	}

	public void CheckNum(int num)
	{
		if (num == 0 && !timebegin)
		{
			FinishState = true;
			isSuccess = true;
		}
	}

	public override void MyEnd()
	{
		base.MyEnd();
		if (instance != null)
		{
			instance = null;
		}
	}

	public override void timeone()
	{
		base.timeone();
		if (!one)
		{
			one = true;
			UIController.instance.show_hitinfo(cur_step.hitinfo);
			UIController.instance.hitinfo_appear();
		}
	}

	public override void timetwo()
	{
		base.timetwo();
		if (!two)
		{
			two = true;
			UIController.instance.show_hitinfo("战斗将在 3 秒后开始");
		}
	}

	public override void timethree()
	{
		base.timethree();
		if (!three)
		{
			three = true;
			UIController.instance.show_hitinfo("战斗将在 2 秒后开始");
		}
	}

	public override void timefour()
	{
		base.timefour();
		if (!four)
		{
			four = true;
			UIController.instance.show_hitinfo("战斗将在 1 秒后开始");
			UIController.instance.hitinfo_disappear();
			creat_NPC();
		}
	}

	public void creat_NPC()
	{
		for (int i = 0; i < cur_step.enemy_id_num.Count; i++)
		{
			AIPool.instance.creat_AI(cur_step.enemy_id_num[i]);
		}
		for (int j = 0; j < cur_step.fri_id_num.Count; j++)
		{
			FriendPool.instance.creat_AI_Fri(cur_step.fri_id_num[j]);
		}
	}
}
